/*
package com.rinlink.gateway.jt808.jt808;

import io.github.hylexus.jt808.session.*;
import io.netty.channel.Channel;
import org.springframework.cache.Cache;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.StringUtils;

import javax.annotation.Nullable;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Stream;

public class RedisJt808SessionManager implements Jt808SessionManager {

    public static final String SESSION_KEY = "jt808-sessions";

    private String sessionKey;

    RedisTemplate redisTemplate;

    ConcurrentMap<String, Jt808Session> sessionMapping = new ConcurrentHashMap<>();

    public RedisJt808SessionManager(String sessionKey, Cache cache) {
        this.sessionKey = StringUtils.isEmpty(sessionKey)? SESSION_KEY : sessionKey;
    }

    @Override
    public Stream<Jt808Session> list() {
        return list(0,20).stream();
    }

    @Override
    public long count() {
        return redisTemplate.opsForList().size(sessionKey);
    }

    @Override
    public Jt808Session generateSession(Channel channel, String terminalId) {
        String sessionId = generateSessionId(channel);
        return new Session()
                .setChannel(channel)
                .setTerminalId(terminalId)
                .setLastCommunicateTimeStamp(System.currentTimeMillis())
                .setId(sessionId);
    }

    @Override
    public void persistence(Jt808Session session) {
        sessionMapping.put(session.getId(),session);
    }

    @Nullable
    @Override
    public Jt808Session removeBySessionId(String sessionId) {
        return sessionMapping.remove(sessionId);
    }

    @Override
    public void removeBySessionIdAndClose(String sessionId, ISessionCloseReason reason) {
        Jt808Session session = sessionMapping.remove(sessionId);
        getEventListener().onSessionClose(session,reason);

    }

    @Override
    public Optional<Jt808Session> findBySessionId(String sessionId) {
        return Optional.ofNullable(sessionMapping.get(sessionKey));
    }

    @Override
    public Optional<Jt808Session> findByTerminalId(String terminalId, boolean updateLastCommunicateTime) {
        return Optional.empty();
    }

    @Override
    public Jt808SessionManagerEventListener getEventListener() {
        return null;
    }

    @Override
    public void setEventListener(Jt808SessionManagerEventListener listener) {

    }
}
*/
